package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.TdormitoryDao;

import com.qfedu.stussm.dto.TdormitoryDto;

import com.qfedu.stussm.entity.Tdormitory;

import com.qfedu.stussm.service.intf.TdormitoryService;

import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TdormitoryServiceImpl implements TdormitoryService {
    @Autowired
    private TdormitoryDao dao;
    @Override
    public R add(Tdormitory tdormitory) {
        if(dao.add(tdormitory) > 0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public PageBeanVo selectLikeAll(String t_name, int page, int limit) {
        PageHelper.startPage(page,limit);
        if(t_name != null && t_name.length() > 0){
            t_name = "%"+t_name+"%";
        }else{
            t_name = null;
        }
        PageInfo<TdormitoryDto> pageInfo = new PageInfo<>(dao.selectLikeAll(t_name));
        return new PageBeanVo(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public R delete(int t_tdid) {
        if(dao.delete(t_tdid) > 0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public R update(Tdormitory tdormitory) {
       if(dao.update(tdormitory) > 0){
           return R.ok();
       }else{
           return R.fail();
       }
    }
}
